home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / polyed.lha / PolyEd / macros / format.ped < prev   
Encoding:
Text File  |  1994-09-29  |  3.3 KB  |  116 lines

  1. /*
  2. ** $VER: format.ped 1.0 (24.8.94) written by Robert Brandner
  3. **
  4. ** This macro formats leftaligned the current paragraph
  5. ** (from the current line to the next empty line).
  6. */
  7.  
  8. OPTIONS RESULTS
  9.  
  10. /* first we get the desired width
  11. ** from the application's settings.
  12. */
  13.  
  14. 'GETATTR' APPLICATION FIELD VAR_RIGHTBORDER VAR WIDTH
  15.  
  16. /* now we get the current line, strip trailing spaces and tabs,
  17. ** and compute it's length
  18. */
  19.  
  20. 'GETLINE' VAR 'LINE'                                 
  21. LINE = strip(LINE, T, " "||'09'X)                    
  22. len = length(LINE)                                   
  23.  
  24. /* prevlen is needed for the while-condition
  25. ** When we join a line with an empty line, len and prevlen
  26. ** will be the same, in which case we stop, as that means,
  27. ** that we reached the end of the paragraph.
  28. */
  29.  
  30. prevlen = 0                                          
  31.  
  32. /* the while-loop:
  33. ** We will leave the loop, when len not greater than prevlen,
  34. ** which means, that we reached an empty line
  35. */
  36.  
  37. do while len > prevlen
  38.  
  39.     /* This loop splits the current line until we get
  40.     ** a line shorter than the desired width.
  41.     */
  42.  
  43.     do while len > WIDTH
  44.  
  45.         /* We move the cursor to the desired right border,
  46.         ** and go to the beginning of the word we find there,
  47.         ** as we don't want to split words.
  48.         */
  49.  
  50.         'GOTOCOLUMN' WIDTH+1
  51.         'POSITION EOW'
  52.         'POSITION SOW'
  53.  
  54.         /* Now we look where we are. If we are at the very
  55.         ** left of the line, this means that there were only
  56.         ** one word from the beginning to column <width>.
  57.         ** In that case, we go to the end of this word, which
  58.         ** leads to a line that is too long, but it is better
  59.         ** than splitting the word.
  60.         */
  61.  
  62.         'GETCURSORPOS' STEM CPOS.
  63.         if CPOS.COLUMN <= 1 then 'POSITION EOW'
  64.  
  65.         /* Now we split the line at the current column, which
  66.         ** results in a line, shorter than <width> (except for
  67.         ** the case with the very long words) and new line
  68.         ** with the rest of the old line.
  69.         ** The cursor is allready at the beginning of this
  70.         ** new line (due to TEXT NEWLINE)
  71.         */
  72.  
  73.         'TEXT NEWLINE'
  74.  
  75.         /* Now we get this new line again (could possibly be made in
  76.         ** an other way too), strip spaces off, and compute
  77.         ** it's length.
  78.         */
  79.  
  80.         'GETLINE' VAR 'LINE'
  81.         LINE = strip(LINE, T, " ")
  82.         len = length(LINE)
  83.     end
  84.  
  85.     /* Here we check if the line is empty, which may happen as a
  86.     ** result of the previous while-loop, and if it's empty, we
  87.     ** leave the outer while-loop immediately.
  88.     */
  89.  
  90.     if len == 0 then leave
  91.  
  92.     /* We remember the length of the current line in <prevlen>.
  93.     ** Now we join the current line (which is shorter than <width>)
  94.     ** and the next line. We insert one blank between the
  95.     ** last word of the current, and the first of the next line.
  96.     ** Then we get this joined line, strip the spaces off, and
  97.     ** compute it's length. If the length is the same as <prevlen>
  98.     ** we know that the following line was empty.
  99.     ** In that case we split the lines again, to keep the empty
  100.     ** line. The while-loop will end in this case too.
  101.     */
  102.  
  103.     prevlen = len
  104.     'POSITION EOL'
  105.     'DELETE'
  106.     'TEXT " "'
  107.     'GETLINE VAR LINE'
  108.     LINE = strip(LINE, T, " ")
  109.     len = length(LINE)
  110.     if prevlen == len then 'TEXT NEWLINE'
  111. end
  112.  
  113. /* And here we are! The paragraph is formated and that's the end of
  114. ** this macro.
  115. */
  116.